#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>
    button {
        background: #758ef0;
        color: #FFF;
        border: none;
        border-radius: 15px;
    }
</style>
#end

#define content()
<div class="layui-fluid">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;color: #009688">
        <legend style="font-size: 20px;font-weight: 500;">企业机构</legend>
    </fieldset>

    <form id="person" class="layui-form" action="">
        <div class="layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label" for="organization"style="width: 180px">组织机构名称</label>
                <div class="layui-input-block " style="margin: 0 180px">
                    <input type="text" id="organization" name="organization" placeholder="#(organization)" value="#(organization)"
                           class="layui-input " style="width: 500px" disabled/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.name" style="width: 180px">企业机构名称</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.name" name="enterprise.name" value="#(organization)"
                           class="layui-input " style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.address"style="width: 180px">公司地址</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.address" name="enterprise.address"
                           value="#(enterprise.address)" lay-verify="required" class="layui-input" style="width: 500px"/>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label" for="enterprise.resume" style="width: 680px;">
                    <h style="margin: 0 50px">公司简介</h>
                </label>
                <div class="layui-input-block">
					<textarea id="enterprise.resume" name="enterprise.resume" lay-verify="required" placeholder=""
                              class="layui-textarea"
                              cols="100" rows="2" wrap="hard" autocomplete="off" style="width: 680px">#(enterprise.resume)</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.principal" style="width: 180px">公司负责人</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.principal" name="enterprise.principal"
                           value="#(enterprise.principal)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.phone"style="width: 180px">公司负责人联系方式</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="tel" id="enterprise.phone" name="enterprise.phone"
                           value="#(enterprise.phone)" lay-verify="required|phone" class="layui-input" style="width: 500px"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.type"style="width: 180px">主体类型</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.type" name="enterprise.type"
                           value="#(enterprise.type)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.credit"style="width: 180px">统一社会信用代码</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.credit" name="enterprise.credit"
                           value="#(enterprise.credit)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.scope"style="width: 180px">业务范围</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.scope" name="enterprise.scope"
                           value="#(enterprise.scope)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.start"style="width: 180px">创办日期</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="date" id="enterprise.start" name="enterprise.start"
                           value="#(enterprise.start)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.person"style="width: 180px">企业法人</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.person" name="enterprise.person"
                           value="#(enterprise.person)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.capital" style="width: 180px">注册资本</label>
                <div class="layui-input-inline" >
                    <input type="number" id="enterprise.capital" name="enterprise.capital" value="#(enterprise.capital)" lay-verify="required|mLength" class="layui-input" style="width: 430px" >
                </div>
                <div class="layui-form-mid layui-word-aux" style="margin:0 240px">元</div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label"style="width: 180px"><em class="require-mark">*</em>法人身份证照片</label>
                <div class="layui-input-block layui-upload" style="align-content: center;">
                    <button type="button" class="layui-btn" id="upload" style="margin: 0 100px"><i
                            class="layui-icon"></i>上传文件
                    </button>
                    <button type="button" class="layui-btn layui-hide " id="see">查看</button>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.website"style="width: 180px">企业网站</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.website" name="enterprise.website"
                           value="#(enterprise.website)" class="layui-input" style="width: 500px" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.landline"style="width: 180px">座机电话</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="enterprise.landline" name="enterprise.landline"
                           value="#(enterprise.landline)" class="layui-input" style="width: 500px" lay-verify="tel"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" for="enterprise.scale" style="width: 180px">企业人数</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="number" id="enterprise.scale" name="enterprise.scale"
                           value="#(enterprise.scale)" class="layui-input" style="width: 500px" lay-verify="required|pLength"/>
                </div>
            </div>

            <div class="layui-form-item layui-hide">
                <label class="layui-form-label" for="source"style="width: 180px">部门资源</label>
                <div class="layui-input-block" style="margin: 0 180px">
                    <input type="text" id="source" name="source"
                           value="#(source)" class="layui-input" style="width: 500px" required/>
                </div>
            </div>
            <!--隐藏flag作为界面是否禁用的方法-->
            <input type="text" id="flag" name="flag"
                   class="layui-input layui-disabled layui-hide" value="#(flag)" required/>
            <input type="text" id="notiId" name="notiId"
                   class="layui-input layui-disabled layui-hide" value="#(notiId)" required/>

            <div class="layui-form-item">
                <div class="layui-input-block" style="margin: 0 180px">
                    <button type="button" class="layui-btn" lay-submit lay-filter="pass" id="pass">通过</button>
                    <button type="button" class="layui-btn layui-btn-warm" lay-submit lay-filter="fail" id="fail">不通过</button>
                    <button type="button" class="layui-btn layui-btn-warm" id="back">返回</button>
                </div>
            </div>
        </div>
    </form>
</div>

#end

#define js()
<script type="text/javascript">
    var fileID, fileFromID;
    layui.use(['form', 'layer', 'upload'], function () {
        var layer = layui.layer
            , $ = layui.jquery
            , form = layui.form
            , upload = layui.upload;

        upload.render({
            elem: '#upload'
            , url: '#(ctxPath)/util/uploadFile'
            , accept: 'file'
            , exts: 'doc|docx|pdf'
            , data: {
                description: "法人身份证照片"
            }, before: function (res) {
                var bg = $('<div class="loading-bg"><i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop loading-ico"></i></div>');
                $('body').prepend(bg);
            }, done: function (res) {
                if (res.code == 0) {
                    $.post('#(ctxPath)/app/organization/upload?fileId=' + res.data.fileId + '&tableName=enterprise&fieldName=法人身份证照片', function (data) {
                        $('.loading-bg').remove();
                        fileFromID = data.fileFromID;
                        layer.msg("上传成功");
                        fileID = res.data.fileId;
                        $('#see').removeClass('layui-hide');
                    });
                } else if (res.code == 1) {
                    $('.loading-bg').remove();
                    layer.msg("文件上传失败，请重新选择上传！");
                    setTimeout(function () {
                    }, 1000);
                }
            }
            , error: function (index, upload) {
                alert("文件上传错误！请重新尝试！");
            }
        });

        form.verify({
            mLength: [
                /^[\S]{0,11}$/
                ,'注册资金不能大于11位'
            ]
            ,tel: [
                /0\d{2,3}-\d{7,8}/
                ,'座机电话格式为000-00000000'
            ]
            ,pLength: [
                /^[\S]{0,9}$/
                ,'人数不能大于9位'
            ]
        });

        form.on('submit(pass)', function (data) {
            util.sendAjax({
                type: 'POST',
                url: '#(ctxPath)'+$("#source").val()+'Review?verify=2',
                data: $.param(data.field),
                loadFlag: true,
                success: function (data) {
                    history.go(-1);
                },
                error: function (data) {
                    console.log(data);
                }
            });
            return false;
        });

        form.on('submit(fail)', function (data) {
            util.sendAjax({
                type: 'POST',
                url: '#(ctxPath)'+$("#source").val()+'Review?verify=1',
                data: $.param(data.field),
                loadFlag: true,
                success: function (data) {
                    history.go(-1);
                },
                error: function (data) {
                    console.log(data);
                }
            });
            return false;
        });
    });

    if ($('#flag').val() == 2) {
        $("#pass").addClass("layui-disabled");
        $("#pass").attr("disabled", "disabled");
    }else if($('#flag').val() == 1){
        $("#fail").addClass("layui-disabled");
        $("#fail").attr("disabled", "disabled");
    }

    $('#back').click(function () {
        history.go(-1);
    });

    $("#see").click(function () {
        pop_show('查看文件', '#(ctxPath)/util/pdfView?fileID=' + fileID, '', '', function () {
        });
    });
</script>
#end
